<?php

namespace App\Services;

use App\Helpers\KeyHandler;
use App\Models\Option;
use Illuminate\Support\Facades\Cache;

class OptionService
{

    /**
     * 获取选择项
     * @param int $type
     * @return mixed
     */
    public static function getOption(int $type): array
    {
        return Cache::remember(sprintf(KeyHandler::OPTION, $type), KeyHandler::OPTION_TTL, function () use ($type) {
            return Option::query()->where('type', $type)
                ->where('status', true)
                ->orderBy('sort')
                ->pluck('name', 'id')->toArray();
        });
    }
}
